home *** CD-ROM | disk | FTP | other *** search
/ Power Bytes: Money & Finance / PowerBytes Money and Finance CD-ROM 01 / PowerBytes Money and Finance CD-ROM 01.iso / New Stuffed Files / ResEdit 1.2b2.sit / Examples / CExamples / ResXXXXEd.c / ResXXXXEd.c
Encoding:
C/C++ Source or Header  |  1988-08-01  |  5.8 KB  |  202 lines  |  [TEXT/MPS ]

  1. /*
  2. File ResXXXXEd.c
  3.  
  4. Copyright Apple Computer, Inc. 1985-1988
  5. All rights reserved.
  6. */
  7.  
  8. #include    <types.h>
  9. #include    <memory.h>
  10. #include    <menus.h>
  11. #include    <resources.h>
  12.  
  13. #include    "ResEd.h"
  14.  
  15. typedef struct rXXXXRec {
  16.     ParentHandle    father;     /*    Back ptr to dad */
  17.     str64            name;        /* the name of this editor */
  18.     WindowPtr        windPtr;    /* This view's window */
  19.     Boolean            rebuild;    /* Set TRUE if things have changed */
  20.     Handle            hXXXX;        /* The resource we are working on */
  21.     MenuHandle        menuXXXX;    /*    our menu */
  22. } rXXXXRec;
  23.  
  24. typedef    rXXXXRec    *rXXXXPtr;
  25. typedef    rXXXXPtr    *rXXXXHandle;
  26.  
  27. pascal void Debugger(/*void*/) extern 0xA9FF;
  28.  
  29. /*- -    -  -  - -  -  -  - -  -  -    - -  -    -  - -    -  -  - -  -  -*/
  30.  
  31. pascal void EditBirth(Handle Thing, ParentHandle Dad)
  32. {
  33.     rXXXXHandle    MyXXXX;
  34.     WindowPtr    w;
  35.     char        s[256];
  36.  
  37.     /* Prepare window title and request creation of a new window */
  38.     strcpy(s, "\pWindow");
  39.     SetETitle((Handle)Thing, s);
  40.     ConcatStr(s, "\p from ");
  41.  
  42.     /*If we got a new window, then start up the editor*/
  43.     if (w = WindSetup(300, 100, s, (*Dad)->name)) {
  44.         FixHand(sizeof(WindowRecord), (Handle)Thing); /* Make sure we have
  45.                                                          enough room in */
  46.         /* the handle for a complete window    */
  47.         /* record. (later this will be        */
  48.         /* assigned to (*MyXXXX)->hXXXX        */
  49.         
  50.         /* Get memory for and handle to our instance record */
  51.         MyXXXX = (rXXXXHandle)NewHandle(sizeof(rXXXXRec)); /* Need to do size
  52.                                                                 check? */
  53.         HLock((Handle)MyXXXX);
  54.         /* Put information about this incarnation of the editor and the window it is */
  55.         /* serving into our record.(always passed around in the handle MyXXXX.         */
  56.  
  57.         (*MyXXXX)->windPtr = w;
  58.         (*MyXXXX)->father = Dad;
  59.         (*MyXXXX)->hXXXX = Thing;
  60.  
  61.         /* Let the main program know who is to manage this window by giving it both    */
  62.         /* our resource ID number and our instance record handle                    */
  63.         ((WindowPeek)w)->windowKind = ResEdID();
  64.         ((WindowPeek)w)->refCon = (long)MyXXXX;
  65.  
  66.         /* Set up menus,the view, etc. for this window */
  67.         HUnlock((Handle)MyXXXX);
  68.     }
  69. }
  70.  
  71. /*- -  -  -    - -  -    -  - -    -  -  - -  -  -  - -  -  -    - -  -    -*/
  72.  
  73. pascal void PickBirth(ResType t,ParentHandle Dad)
  74. {
  75. }
  76. /*- -  -  -    - -  -    -  - -    -  -  - -  -  -  - -  -  -    - -  -    -*/
  77.  
  78. pascal void DoEvent(EventRecord *Evt, rXXXXHandle MyXXXX)
  79. {
  80.     Point    MousePoint;
  81.  
  82.     BubbleUp((Handle)MyXXXX);    /* Move our item up im memory */
  83.     HLock((Handle)MyXXXX);        /* Lock it down */
  84.     /* Handle event passed to us by main program    */
  85.     /* Just like a 'real' event loop, exceptâ•”        */
  86.     /* there is no loop and we don't have to        */
  87.     /* handle as much because the main program        */
  88.     /* will do all the stuff that doesn't apply        */
  89.     /* to us.                                        */
  90.     MousePoint = Evt->where;    /* Point at which the event occured */
  91.     SetPort((*MyXXXX)->windPtr);/* Set the port to our window */
  92.     GlobalToLocal(&MousePoint);    /* Convert event location to local coords */
  93.     switch (Evt->what) {
  94.         case mouseDown:
  95.             break;
  96.  
  97.         case activateEvt:
  98.             AbleMenu(FileMenu, fileTop);
  99.             if (Evt->modifiers & activeFlag) {
  100.                 /* Activate event */
  101.             } else {
  102.                 /* Deactivate event */
  103.             }
  104.             break;
  105.  
  106.         case updateEvt:
  107. PaintRect(&(*MyXXXX)->windPtr->portRect);
  108.             break;
  109.  
  110.         case keyDown:
  111.             break;
  112.  
  113.     }
  114.     HUnlock((Handle)MyXXXX);
  115. }
  116. /*- -  -  -    - -  -    -  - -    -  -  - -  -  -  - -  -  -    - -  -    -*/
  117.  
  118. pascal void DoInfoUpdate(short oldID, short newID, rXXXXHandle MyXXXX)
  119. {
  120.     char    s[256];
  121.  
  122.     /* Since our ID has changed, we need to change our window title */
  123.     strcpy(s, "\pWindow");
  124.     SetETitle((Handle)(*MyXXXX)->hXXXX, s);
  125.     ConcatStr(s, "\p from ");
  126.     ConcatStr(s, (*((*MyXXXX)->father))->name);
  127.     SetWTitle((*MyXXXX)->windPtr, s);
  128.  
  129.     /* Now, let our father object know that our ID has been changed */
  130.     CallInfoUpdate(oldID, newID, (*((*MyXXXX)->father))->wind->refCon,
  131.                  (*((*MyXXXX)->father))->wind->windowKind);
  132. }
  133. /*- -  -  -    - -  -    -  - -    -  -  - -  -  -  - -  -  -    - -  -    -*/
  134.  
  135. static void DoClose(rXXXXHandle MyXXXX)
  136. {
  137.     CloseWindow((*MyXXXX)->windPtr);    /* Close the window */
  138.     WindFree((*MyXXXX)->windPtr);        /* Mark the window record as being available */
  139.     InitCursor();                        /* Make sure the cursor is the arrow cursor */
  140.     /* Delete any menus that we added and redraw menu bar    */
  141.     /* Be sure to dispose of any handles you are done with    */
  142.     DisposHandle((Handle)MyXXXX);
  143. }
  144.  
  145. pascal void DoMenu(short Menu, short Item, rXXXXHandle MyXXXX)
  146. {
  147.     short    saveRefNum;
  148.  
  149.     BubbleUp((Handle)MyXXXX);
  150.     HLock((Handle)MyXXXX);
  151.     SetPort((*MyXXXX)->windPtr);        /* Set the port to our window */
  152.  
  153.     /* Again, we handle the menu stuff just as we would in a 'real' application    */
  154.     /* except that we only have to handle those items that apply to ourselves.    */
  155.     switch (Menu) {
  156.         case FileMenu:
  157.             switch (Item) {
  158.                 case CloseItem:
  159.                     DoClose(MyXXXX);    /* Close our window */
  160.                     return;                /* Return to main program */
  161.                     break;
  162.         
  163.                 case RevertItem:
  164.                     /* The area under window will need to be updated */
  165.                     InvalRect(&(*MyXXXX)->windPtr->portRect);
  166.                     
  167.                     /* We will need to restore the cur resource file    */
  168.                     /* reference number when we are done here.            */
  169.                     saveRefNum = CurrentRes();
  170.                     
  171.                     /* We are going to be using the resource file we    */
  172.                     /* came from.                                        */
  173.                     UseResFile(HomeResFile((Handle)(*MyXXXX)->hXXXX));
  174.                     
  175.                     /* Read in the old copy from disk (see documentation*/
  176.                     /* for revertResource).  Clear it out unless this    */
  177.                     /* was a newly created resource, in which case        */
  178.                     /* don't.                                            */
  179.                     if (!RevertResource((Handle)(*MyXXXX)->hXXXX)) {
  180.                         RmveResource((Handle)(*MyXXXX)->hXXXX);
  181.                         (*((*MyXXXX)->father))->rebuild = true;
  182.                         DoClose;
  183.                         return;
  184.                     }
  185.                     /* Go back to using old resource file. */
  186.                     UseResFile(saveRefNum);
  187.                     break;
  188.                     
  189.                 case GetInfoItem:
  190.                     ShowInfo((Handle)(*MyXXXX)->hXXXX, (ParentHandle)MyXXXX);
  191.                     break;
  192.             }
  193.  
  194.         case EditMenu:
  195.             switch (Item) {
  196.                 case CutItem:    break;
  197.                 case CopyItem:    break;
  198.                 case PasteItem:    break;
  199.                 case ClearItem:    break;
  200.             }
  201.     }
  202. }